import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/routes.dart';
import 'package:ytbusiness/utils/asset_util.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

///主页抽屉
class DrawerLayout extends StatefulWidget {
  @override
  _DrawerLayoutState createState() => _DrawerLayoutState();
}

class _DrawerLayoutState extends State<DrawerLayout> {
  List<String> _titleList = ["店铺信息", "账号设置", "切换账号", "退出登录"];
  List<String> images = ["dianpu.png", "user.png", "qiehuan.png", "tuichu.png"];

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: SafeArea(
        child: SingleChildScrollView(
          child: Column(
            children: [
              SizedBox(
                height: setWidth(28),
              ),
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(
                    width: setWidth(19),
                  ),
                  Container(
                    height: setWidth(60),
                    width: setWidth(60),
                    decoration: BoxDecoration(
                        color: Color(0xffC4C4C4),
                        borderRadius: BorderRadius.circular(30)),
                  ),
                  SizedBox(
                    width: setWidth(12),
                  ),
                  Expanded(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          child: Text(
                            "汽车养护中心",
                            style: TextStyle(
                                color: Color(0xff323232),
                                fontSize: setSp(16),
                                fontWeight: FontWeight.w600),
                          ),
                        ),
                        SizedBox(
                          height: setWidth(10),
                        ),
                        Container(
                          child: Text(
                            "ID:15245898476",
                            style: TextStyle(
                                color: Color(0xff686868), fontSize: setSp(12)),
                          ),
                        )
                      ],
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      //去扫描
                      urlPush(
                          context, RouteManager.route(RouteManager.scanner));
                    },
                    child: Container(
                      padding: EdgeInsets.only(
                          left: setWidth(15), right: setWidth(15)),
                      child: Image.asset(AssetUtil.icon('ic_scan'),
                          width: setWidth(17), height: setWidth(17)),
                    ),
                  )
                ],
              ),
              Container(
                margin: EdgeInsets.only(left: setWidth(16), top: setWidth(20)),
                child: ListView.builder(
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: _titleList.length,
                    itemBuilder: (context, index) {
                      return GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            switch (index) {
                              case 0:
                                urlPush(context, RouteManager.route(RouteManager.myStore));
                                break;
                              case 1:
                                urlPush(context, RouteManager.route(RouteManager.accountSetting));
                                break;
                              case 2:
                                urlPush(context, RouteManager.route(RouteManager.checkRole));
                                break;
                            }
                          },
                          child: _item(_titleList[index], images[index],
                              type: index));
                    }),
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _item(String title, String image, {int type}) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: EdgeInsets.only(top: setWidth(20)),
          child: Row(
            children: [
              Container(
                child: Image.asset(
                  "assets/images/$image",
                  fit: BoxFit.cover,
                ),
                width: setWidth(20),
                height: setWidth(20),
              ),
              SizedBox(
                width: setWidth(11),
              ),
              Container(
                child: Text.rich(
                  TextSpan(children: [
                    TextSpan(
                      text: title,
                      style: TextStyle(
                          color: Color(0xff323232), fontSize: setSp(16)),
                    ),
                    TextSpan(
                      text: type == 0 ? "(暂不可修改)" : "",
                      style: TextStyle(
                          color: Color(0xffec0101), fontSize: setSp(10)),
                    ),
                  ]),
                  textAlign: TextAlign.center,
                ),
              )
            ],
          ),
        ),
        SizedBox(
          height: setWidth(15),
        ),
        Container(
          margin: EdgeInsets.only(left: setWidth(16)),
          height: setWidth(0.5),
          color: Color(0xffF0F0F0),
        ),
      ],
    );
  }
}
